import * as apis from '../services/uploadFileService.js'

export default {
    namespace:'uploadFile',

    state:{
        informationList:[]
    },

    reducers:{
        setInformationList:setInformationList
    },

    effects:{
       uploadFile:uploadFile,
       queryFile:queryFile,
       deleteFile:deleteFile
    }
}

function setInformationList(state,payload){
    let _state = JSON.parse(JSON.stringify(state));
    _state.informationList = payload.data;
    return _state
}

/**
 * 管理员删除已上传资料
 */
function* deleteFile(payload,{select,call,put}){
    let result = yield call(apis.deleteFile,payload.data)
}

/**
 * 管理员上传文件至服务器
 */
function* uploadFile(payload,{select,call,put}){
    let result = yield call (apis.uploadFile,payload.data)
    yield put({
        type:"app/setServerRes",
        data:result.data
    })
}

/**
 * 按类型查找文件
 */
function* queryFile(payload,{select,call,put}){
    let result = yield call (apis.queryFile,payload.data)

    yield put({
        type:"uploadFile/setInformationList",
        data:result.data.data
    })
}

